﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Web.Security;
using System.Data;
using System.Data.SqlClient;

namespace School_Management
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void LoginButton_Click(object sender, EventArgs e)
        {
            string userName = UserName.Text;
            string password = Password.Text;

            string strcon = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
            SqlConnection con = new SqlConnection(strcon);
            con.Open();
            //string cmdtext = "select count(*) from Users where UserName = '" + userName + "' and password='" + password + "'";
            string cmdtext = "select * from Users where UserName = '" + userName + "' and password='" + password + "'";
            SqlCommand cmd = new SqlCommand(cmdtext,con);
            //int count  = Convert.ToInt32(cmd.ExecuteScalar());
            SqlDataReader rdr = cmd.ExecuteReader();
            if (rdr != null)
            {
                if (rdr.Read())
                {
                    Session["User_Id"] = rdr["Id"].ToString();
                    FormsAuthentication.RedirectFromLoginPage(userName, RememberMe.Checked);
                }
                else
                {
                    lblError.Visible = true;
                }
            }
             
            
       }
    }
}